<?php
/**
 * 活动参数设置
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-04-27
 * Time: 下午 7:11
 */
namespace App;

use Model\ActivitySettingMod;

class ActivitySetting extends Action
{
    private $ActivitySetting = null;
	public function __construct()
	{
		parent::__construct();
		$this->ActivitySetting = new ActivitySettingMod();
	}

    /**
     * 参数设置
     * @param data  data=>array('a'=>1,'b'=>2) 参数字段数据
     */
	public function setting()
    {
        $_setting = $this->ActivitySetting->findOne(array('activity_id'=>$this->_gpc['activity_id']),array('id'));
        if($_setting){
            if($this->ActivitySetting->update($this->_gpc['data'],array('id'=>$_setting['id']))){
                $this->_result = array('status'=>'success');
            }
        }else{
            $this->_gpc['data']['activity_id'] = $this->_gpc['activity_id'];
            if($this->ActivitySetting->insert($this->_gpc['data'])){
                $this->_result = array('status'=>'success');
            }
        }
        $this->result($this->_result);
    }

    /**
     * 获取setting
     * @param activity_id 活动id
     */
    public function getSetting()
    {
        $_setting = $this->ActivitySetting->findOne(array('activity_id'=>$this->_gpc['activity_id']),$this->_gpc['return']);
        if(!$_setting){
            $_data = array('activity_id'=>$this->_gpc['activity_id'],'coupon_check'=>2);
            $this->ActivitySetting->insert($_data);
            $this->getSetting();
        }
        $this->_result = array('status'=>'success','data'=>$_setting);
        $this->result($this->_result);
    }


}